home *** CD-ROM | disk | FTP | other *** search
- //https://developer.mozilla.org/en/Chrome/Command_Line
-
- const nsISupports = Components.interfaces.nsISupports;
- const nsICategoryManager = Components.interfaces.nsICategoryManager;
- const nsIComponentRegistrar = Components.interfaces.nsIComponentRegistrar;
- const nsICommandLine = Components.interfaces.nsICommandLine;
- const nsICommandLineHandler = Components.interfaces.nsICommandLineHandler;
- const nsIFactory = Components.interfaces.nsIFactory;
- const nsIModule = Components.interfaces.nsIModule;
- const nsIWindowWatcher = Components.interfaces.nsIWindowWatcher;
-
- const CHROME_URI = "chrome://sqlitemanager/content/";
- const clh_contractID = "@mrinalkant/commandlinehandler/general-startup;1?type=sqlitemanager";
-
- // use uuidgen to generate a unique ID
- const clh_CID = Components.ID("{f15ff0f9-9699-496e-a13c-a651365abe2a}");
-
- // category names are sorted alphabetically. Typical command-line handlers use a
- // category that begins with the letter "m".
- const clh_category = "m-sqlitemanager";
-
- /**
- * Utility functions
- */
-
- /**
- * Opens a chrome window.
- * @param aChromeURISpec a string specifying the URI of the window to open.
- * @param aArgument an argument to pass to the window (may be null)
- */
- function openWindow(aChromeURISpec, aArgument)
- {
- var ww = Components.classes["@mozilla.org/embedcomp/window-watcher;1"].
- getService(Components.interfaces.nsIWindowWatcher);
- ww.openWindow(null, aChromeURISpec, "_blank",
- "chrome,menubar,toolbar,status,resizable,dialog=no",
- aArgument);
- }
-
- /**
- * The XPCOM component that implements nsICommandLineHandler.
- * It also implements nsIFactory to serve as its own singleton factory.
- */
- const myAppHandler = {
- /* nsISupports */
- QueryInterface : function clh_QI(iid)
- {
- if (iid.equals(nsICommandLineHandler) ||
- iid.equals(nsIFactory) ||
- iid.equals(nsISupports))
- return this;
-
- throw Components.results.NS_ERROR_NO_INTERFACE;
- },
-
- /* nsICommandLineHandler */
-
- handle : function clh_handle(cmdLine)
- {
- var args = Components.classes["@mozilla.org/supports-string;1"]
- .createInstance(Components.interfaces.nsISupportsString);
- try {
- // command line flag that takes an argument
- var uristr = cmdLine.handleFlagWithParam("sqlitemanager", false);
- if (uristr != null) {
- // convert uristr to an nsIURI
- args.data = cmdLine.resolveURI(uristr).path;
- openWindow(CHROME_URI, args);
- cmdLine.preventDefault = true;
- }
- }
- catch (e) {
- Components.utils.reportError("incorrect parameter passed to -sqlitemanager on the command line." + e.name + uristr);
- openWindow(CHROME_URI, null);
- cmdLine.preventDefault = true;
- }
-
- // command line flag (no argument)
- if (cmdLine.handleFlag("anotherflag", false)) {
- //TODO: whatever you want
- cmdLine.preventDefault = true;
- }
- },
-
- // CHANGEME: change the help info as appropriate, but
- // follow the guidelines in nsICommandLineHandler.idl
- // specifically, flag descriptions should start at
- // character 24, and lines should be wrapped at
- // 72 characters with embedded newlines,
- // and finally, the string should end with a newline
- helpInfo : " -sqlitemanager Open SQLite Manager\n" +
- " -sqlitemanager <uri> Open the URI in SQLite Manager\n",
-
- /* nsIFactory */
-
- createInstance : function clh_CI(outer, iid)
- {
- if (outer != null)
- throw Components.results.NS_ERROR_NO_AGGREGATION;
-
- return this.QueryInterface(iid);
- },
-
- lockFactory : function clh_lock(lock)
- {
- /* no-op */
- }
- };
-
- /**
- * The XPCOM glue that implements nsIModule
- */
- const myAppHandlerModule = {
- /* nsISupports */
- QueryInterface : function mod_QI(iid)
- {
- if (iid.equals(nsIModule) ||
- iid.equals(nsISupports))
- return this;
-
- throw Components.results.NS_ERROR_NO_INTERFACE;
- },
-
- /* nsIModule */
- getClassObject : function mod_gch(compMgr, cid, iid)
- {
- if (cid.equals(clh_CID))
- return myAppHandler.QueryInterface(iid);
-
- throw Components.results.NS_ERROR_NOT_REGISTERED;
- },
-
- registerSelf : function mod_regself(compMgr, fileSpec, location, type)
- {
- compMgr.QueryInterface(nsIComponentRegistrar);
-
- compMgr.registerFactoryLocation(clh_CID,
- "myAppHandler",
- clh_contractID,
- fileSpec,
- location,
- type);
-
- var catMan = Components.classes["@mozilla.org/categorymanager;1"].
- getService(nsICategoryManager);
- catMan.addCategoryEntry("command-line-handler",
- clh_category,
- clh_contractID, true, true);
- },
-
- unregisterSelf : function mod_unreg(compMgr, location, type)
- {
- compMgr.QueryInterface(nsIComponentRegistrar);
- compMgr.unregisterFactoryLocation(clh_CID, location);
-
- var catMan = Components.classes["@mozilla.org/categorymanager;1"].
- getService(nsICategoryManager);
- catMan.deleteCategoryEntry("command-line-handler", clh_category);
- },
-
- canUnload : function (compMgr)
- {
- return true;
- }
- };
-
- /* The NSGetModule function is the magic entry point that XPCOM uses to find what XPCOM objects
- * this component provides
- */
- function NSGetModule(comMgr, fileSpec)
- {
- return myAppHandlerModule;
- }
-
-